﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="PageACLManage.aspx.cs" Inherits="ProjectStudy.PageACLManage.PageACLMondify" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
    <script src="../Scripts/jquery-1.4.1.js" type="text/javascript"></script>
    <script src="../Scripts/jquery-1.4.1.min.js" type="text/javascript"></script>
    <script src="../Scripts/jquery-1.4.1-vsdoc.js" type="text/javascript"></script>

    <style type="text/css">
table.altrowstable {
	font-family: verdana,arial,sans-serif;
	font-size:14px;
	color:#333333;
	border-width: 1px;
	border-color: #a9c6c9;
	border-collapse: collapse;
}
table.altrowstable th {
	border-width: 1px;
	padding: 8px;
	border-style: solid;
	border-color: #a9c6c9;
}
table.altrowstable td {
	border-width: 1px;
	padding: 8px;
	border-style: solid;
	border-color: #a9c6c9;
}
.oddrowcolor{
	background-color:#d4e3e5;
}
.evenrowcolor{
	background-color:#c3dde0;
}
</style>

    <script type="text/javascript">
        $(function () {
            $.ajax({
                type: "post",
                url: "../Ajax/Menu_Manage.ashx",
                data: { "action": "GetGroup" },
                dataType: "json",
                success: function (data) {
                    $.each(data, function (index, item) {
                        $("#selGroup").append('<option id="' + 'op' + (index + 1) + '">' + item.GroupName + '</option>');
                        $("#selGroup2").append('<option id="' + 'opt' + (index + 1) + '" value="' + item.class + '">' + item.GroupName + '</option>');
                    });
                }
            });

            $("#btnSearch").click(function () {
                $("#tb1").html("");
                var group = $("#selGroup").find("option:selected").text();
                $.ajax({
                    type: "post",
                    url: "../Ajax/Ajax_PageACLManage.ashx",
                    data: { "action": "GetPageACLList", "group": group },
                    dataType: "json",
                    success: function (data) {
                        if (data != null && data != '') {
                            $("#tb1").append('<tr id="tr0"></tr>');
                            $("#tr0").append('<td><input type="checkbox" id="cbkAll"/></td>');
                            $("#tr0").append('<td>序号</td>');
                            $("#tr0").append('<td>页面ID</td>');
                            $("#tr0").append('<td>页面URL</td>');
                            $("#tr0").append('<td>页面权限等级</td>');
                            $("#tr0").append('<td>页面用户组</td>');
                            $.each(data, function (index, item) {
                                $("#tb1").append('<tr id="tr' + (index + 1) + '"></tr>');
                                $("#tr" + (index + 1)).append('<td><input type="checkbox" name="chkItem"/></td>');
                                $("#tr" + (index + 1)).append('<td>' + (index + 1) + '</td>');
                                $("#tr" + (index + 1)).append('<td>' + item.PageId + '</td>');
                                $("#tr" + (index + 1)).append('<td>' + item.PageURL + '</td>');
                                $("#tr" + (index + 1)).append('<td>' + item.PageRightClass + '</td>');
                                $("#tr" + (index + 1)).append('<td>' + item.PageUserGroup + '</td>');
                            });
                            $("#cbkAll").click(function () {
                                $("input[name='chkItem']").attr("checked", $("#cbkAll").attr("checked"));
                            });
                        }
                        else {
                            alert("没有数据");
                        }
                    }
                });
            });

            $("#btnSet").click(function () {
                FnUpdatePageACL();
            });

            $("#btnDel").click(function () {
                FnPageACLDel();
            });

            $("#btnAdd").click(function () {
                window.location.href = "/PageACLManage/PageACLAdd.aspx";
            });
        });

        function FnUpdatePageACL() {
            var chks = $("input[name='chkItem']");
            var arr = [];
            var arrTr = [];
            var arrURL = [];
            for (var i = 0; i < chks.length; i++) {
                if (chks[i].checked) {
                    arrTr.push($(chks[i]).parent().parent().attr('id'));
                    arr.push($(chks[i]).parent().next().next().html());
                }
            }
            if (arr.length <= 0) {
                alert("请选择一行数据");
            }
            else {
                if (confirm("确认更新?") == true) {
                var group=$("#selGroup2").find("option:selected").text();
                var rightClass=$("#selGroup2").val();
                $.ajax({
                    type: "Post",
                    url: "../Ajax/Ajax_PageACLManage.ashx",
                    data: { "action": "UpdatePageACL", "PageId": JSON.stringify(arr), "group": group, "class": rightClass },
                    dataType: "json",
                    success: function (data) {
                        if (data["status"] == "success") {
                            for (var i = 0; i < arrTr.length; i++) {
                                $("#" + arrTr[i]).children().first().next().next().next().next().html(rightClass);
                                $("#" + arrTr[i]).children().first().next().next().next().next().next().html(group);
                            }
                        }
                        else if (data["status"] == "updateErr") {
                            alert(data["errMsg"] + "页面更新失败");
                        }
                        else if (data["status"] == "noData") {
                            alert("请选中有URL地址的数据行");
                        }
                    },
                    error: function (err) {
                        alert(err);
                    }
                });
                }
            }
        }

        function FnPageACLDel() {
            var chks = $("input[name='chkItem']");
            var arr = [];
            var arrTr = [];
            for (var i = 0; i < chks.length; i++) {
                if (chks[i].checked) {
                    arrTr.push($(chks[i]).parent().parent().attr('id'));
                    arr.push($(chks[i]).parent().next().next().html());
                }
            }
            if (arr.length <= 0) {
                alert("请最少选择一行数据");
            }
            else {
                if (confirm("确认删除?") == true) {
                    $.ajax({
                        type: "Post",
                        url: "../Ajax/Ajax_PageACLManage.ashx",
                        data: { "action": "DelPageACL", "PageId": JSON.stringify(arr) },
                        dataType: "json",
                        success: function (data) {
                            if (data["status"] == "success") {
                                for (var i = 0; i < arrTr.length; i++) {
                                    $("#" + arrTr[i]).remove();
                                }
                            }
                            else if (data["status"] == "updateErr") {
                                alert(data["errMsg"] + "页面删除失败");
                            }
                            else if (data["status"] == "noData") {
                                alert("请选中有URL地址的数据行");
                            }
                        },
                        error: function (err) {
                            alert(err);
                        }
                    });
                }
            }
        }

    </script>  
</head>
<body>
    <form id="form1" runat="server">
    <div>
    <label style=" height:30px; line-height:30px; font-size:16px;">用户组</label>
    <select id="selGroup" style=" height:30px; line-height:30px; font-size:16px;">
      <option id="op0">all</option>
    </select>
    <input  type="button" id="btnSearch" value="查询" style=" height:30px; line-height:30px; font-size:16px;"/>
    <br />
    <br />
    <select id="selGroup2" style=" height:30px; line-height:30px; font-size:16px;">
      
    </select>
    <input  type="button" id="btnSet" value="设置" style=" height:30px; line-height:30px; font-size:16px;"/>
    <input  type="button" id="btnDel" value="删除" style=" height:30px; line-height:30px; font-size:16px;"/>
    <input  type="button" id="btnAdd" value="新增" style=" height:30px; line-height:30px; font-size:16px;"/>
    <br />
    <br />
    <table id="tb1" border="1" cellpadding="0" cellspacing="0" class="altrowstable">
      
    </table>
    </div>
    </form>
</body>
</html>
